
<!--HEADER-->
{include file="Public/header"/}
<!--HEADER-->
<div class="clearfix clearfix20"></div>
<div class="container">
    <div class="row">
		 {include file="Public/readme"/}
        <div class="col-sm-9">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title">在线充值</h3>
                </div>

                <div class="panel-body">

                    <div id="myTabsZjglConten" class="tab-content">
                        <!--会员充值-->
                        <div role="tabpanel" class="tab-pane fade in active" id="tChzh">
                            <div class="col-sm-9 payCzjk">
                                <table class="table table-responsive">
                                    <tbody><tr>
                                        <th class="text-right ft14" style="width: 120px;">充值方式：</th>
                                        <td><label class="payType ft14">
                                        	 <a href="/home/Recharge/recharge" class="btn btn-primary active cursorD" >在线充值</a>
                                        </label>
                                            <label class="payType ft14">
                                              <a href="/home/Ofrecharge/ofrecharge" class="btn btn-default cursorD" >线下充值</a>
                                            </label></td>
                                    </tr>
                                    </tbody>
                              <form class="form-horizontal" role="form" action="/home/Recharge/order" method="post" enctype="multipart/form-data">
                                    <tbody class="payLine">
                                <tr>
                                    <th class="text-right ft14">充值金额：</th>
                                    <td>
                                        <div class="input-group col-md-5 pull-left">
                                           <input type="number" class="form-control" id="amount" name="amount" value=""
                                           placeholder="充值金额" step="0.01"  onkeypress="return checkNumber(event,this);">
                                            <div class="input-group-addon">元</div>
                                        </div>
                                        <p class="help-block pull-left onlineTip" id="xxf">　　　(手续费：0%)</p>
                                    </td>
                                </tr>
                                <tr>
                                    <th class="text-right ft14">充值费用：</th>
                                    <td id="fy">0.00 <b>元</b></td>
                                </tr>
                                <tr>
                                    <th class="text-right ft14">实付金额：</th>
                                    <td id="Actualamount">0.00
                                        <b>元</b>
                                    </td>
                                </tr>

                                <tr>
                                    <th class="text-right ft14">充值接口：</th>
                                    <td class="payCzjkWarp">
						                        <input type="hidden" name="typepay" id="typepay" value="">
						                        <input type="hidden" name="min" id="moneyMin" value="{$min}">
						                        {foreach  name='payments' item='v' }
						                        <p onclick="test(this)" data-code="{$v.id}" ser="{$v.ServiceCharge}">
						                            <span>
						                                <img src="/static/home/images/{$v.photo}"alt="{$v.payName}">
						                            </span><br>
						                            <span>{$v.commit}</span>
						                        </p>
						                        {/foreach}
                                    </td>
                                </tr>
                                </tbody>
                                  <tbody><tr>
                                        <th></th>
                                        <td>
                                            <button class="btn btn-danger">&nbsp;&nbsp;&nbsp;充值&nbsp;&nbsp;&nbsp;
                                            </button>
                                        </td>
                                    </tr>
                                    </tbody>
                                </table>
                            </div>
                            <div class="col-sm-9">
                                <ul class="list-unstyled">
                                    <li>1</li>
                                    <li>2</li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </form>
                </div>
            </div>
        </div>
    </div>
</div>

<!--footer-->
{include file="Public/footer"/}

<script>

    $("#collapseOne").find(".list-group").find("li").eq(0).addClass("active");

    function test($this) {

        //获取充值金额
        var amount = $("input[name='amount']").val();
        var min = $("input[name='min']").val();

        datacode = $($this).attr('data-code');
        ser = $($this).attr('ser');
        $("#xxf").html("　　(手续费："+(ser*100).toFixed(2)+"%)");
        //最小金额
        if(amount <min){
            alert('最低金额不小于'+min+'元');
            return false;
        }
        if(datacode==1 ||datacode==11){
            if(($("input[name='amount']").val())%1==0){
                alert('本充值方式金额请带零头，如：3500'+'.'+Math.floor(Math.random()*10)+Math.floor(Math.random()*10)+'或18500'+'.'+Math.floor(Math.random()*10)+Math.floor(Math.random()*10));
                window.location.href='/home/Recharge/recharge';
//            return false;
            }
        }

        //费用
        var fy = amount*ser;//).toFixed(4)
        //实际金额
        var Actualamount = Number(amount)+fy;
        $("#fy").html(fy+"元");
        $("#Actualamount").html(Actualamount.toFixed(2));
        $("#typepay").val(datacode);
       // alert(datacode);


    }

    //线上充值
    $(".payCzjkWarp").find("p").each(function (index) {
        $(this).click(function () {
            $(this).addClass("active").siblings("p").removeClass("active");
            //alert(index);
        });
    });

/*    // 线上
    var formData = new FormData();
    formData.append("amount", $("input[name='amount']").val());
    formData.append("numbers", datacode);
    //alert($("input[name='amount']").val());return false;
    //          formData.append("toamount",document.getElementById("Actualamount").value);
    formData.append("toamount",$("#Actualamount").text());
     alert(1111);
    if(datacode==1){
        if(($("input[name='amount']").val())%1==0){
            alert('免手续支付宝必须是带几角几分的金额，比如：9999'+'.'+Math.floor(Math.random()*10)+Math.floor(Math.random()*10)+'或者10000'+'.'+Math.floor(Math.random()*10)+Math.floor(Math.random()*10));
            window.location.href='http://www.lc2.com/home/Recharge/recharge';
//            return false;
        }
    }

//            var tempWin = window.open("","_blank")
    $.ajax({
        url: '/home/Recharge/order',
        type: 'POST',
        data: formData,
        processData: false,
        contentType: false,
        success: function (data) {
            console.log(data);
//                    tempWin.location = data;
//                  window.open(data);
            window.location.href=data;
            //window.open('http://www.imooc.com','_blank','width=600,height=400,top=100px,left=0px');
//                  var obj = JSON.parse(data);
//                  if (obj.msg == 'success') {
//                      alert('资料提交成功');
//                  } else {
//                      alert(obj.msg);
//                  }
            // console.log(data);
            // alert(data)
        }
    });*/

</script>
<script>
    function checkNumber(e, txt) {
        var key = window.event ? e.keyCode : e.which;
        var keychar = String.fromCharCode(key);
        reg = /\d|\./;
        var result = reg.test(keychar);
        if (result) {
            if (e.keyCode == 46)
                result = !(txt.value.split('.').length > 1);
            else
                result = !(txt.value.split('.').length > 1 && txt.value.split('.')[1].length > 1);
        }
        if (!result) {
            return false;
        }
        else {
            return true;
        }
    }
</script>